# c-examples/any/makefile
#
# WARNING: this makefile isn't safe for parallel making!
#
#  compile the any example
#
# MS 92
#
# $Header: /usr/app/odstb/CVS/snacc/c-examples/any/makefile,v 1.6 1995/07/24 20:42:31 rj Exp $
# $Log: makefile,v $
# Revision 1.6  1995/07/24 20:42:31  rj
# useful.asn1 renamed to asn-useful.asn1 to accomodate to snacc's new file name generation scheme.
# any-test.[hc] becomes any.[hc] due to to snacc's new file name generation scheme.
#
# `cd && make' instead of `cd; make'.
#
# changed `_' to `-' in file names.
#
# Revision 1.5  1995/02/20  11:51:39  rj
# build snacc if it doesn't exist.
# some makes leave a trailing slash on $(@D), others don't. this causes some mkdir(1)s to deny their cooperation. therefore, the slash has got to be stripped.
#
# Revision 1.4  1995/02/13  15:05:05  rj
# augment CPPFLAGS, not overwrite.
# use $(@D) and $(@F) instead of `dirname $@` and `basename $@` (not every system's got the commands).
# we need the compiler for the dependencies, so make it if it doesn't yet exist.
#
# Revision 1.3  1994/08/31  21:41:37  rj
# rebuild the executables when the c-lib is newer.
#
# Revision 1.2  1994/08/31  10:31:49  rj
# since .o files get moved, a few more dependencies are needed.
#
# Revision 1.1  1994/08/31  08:46:20  rj
# first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
#

#include ../../makehead

TOP		= /usr

ASN1_SRC_DIR	= $(TOP)/include/snacc/asn1

ASN1_C_LIB_DIR	= $(TOP)/lib
ASN1_C_INC_DIR	= $(TOP)/include/snacc/c
ASN1_C_LIB	= $(ASN1_C_LIB_DIR)/libasn1csbuf.a

COMPILERDIR	= $(TOP)/bin
SNACC		= $(COMPILERDIR)/snacc
USEFUL_TYPES	= $(ASN1_SRC_DIR)/asn-useful.asn1
SNACCFLAGS	= -u $(USEFUL_TYPES)

CPPFLAGS	+= -g -I$(TOP) -I$(ASN1_C_INC_DIR) -DUSE_SBUF $(LENFLAG)
LIBS		+= -lm

ASN1FILES	= $(ASN1_SRC_DIR)/any.asn1

# generated by snacc from any.asn1:
ASN1HFILES	= any.h
ASN1CFILES	= any.c

CFILES = \
	genber.c	\
	example.c

DISTFILES = \
	README		\
	makefile	\
	$(CFILES)

#-------------------------------------------------------------------------------

all::		genber def indef

$(ASN1HFILES)	\
$(ASN1CFILES):	$(SNACC) $(ASN1FILES)
		$(REASON)
		$(SNACC) $(SNACCFLAGS) $(ASN1FILES)

$(SNACC):
		cd $(@D) && $(MAKE) $(@F)

def-obj		\
indef-obj:
		mkdir $@

def-obj/any.o	\
def-obj/example.o:
		$(REASON)
		$(MAKE) LENFLAG= `echo $(@D) | sed -e 's:/$$::'` $(@F)
		mv $(@F) $@

indef-obj/any.o	\
indef-obj/example.o:
		$(REASON)
		$(MAKE) LENFLAG=-DUSE_INDEF_LEN `echo $(@D) | sed -e 's:/$$::'` $(@F)
		mv $(@F) $@

genber:		def-obj/any.o genber.o
		$(REASON)
		$(CC) $(LDFLAGS) -o $@ def-obj/any.o genber.o $(ASN1_C_LIB) $(LIBS)

def: 		def-obj/any.o def-obj/example.o
		$(REASON)
		$(CC) $(LDFLAGS) -o $@ def-obj/any.o def-obj/example.o $(ASN1_C_LIB) $(LIBS)

indef:		indef-obj/any.o indef-obj/example.o
		$(REASON)
		$(CC) $(LDFLAGS) -o $@ indef-obj/any.o indef-obj/example.o $(ASN1_C_LIB) $(LIBS)

genber	\
def	\
indef:		$(ASN1_C_LIB)

.PHONY:	check

check::		genber def indef
		$(RM) foo.ber bar.ber
		./genber
		./indef att.ber > foo.ber
		./def foo.ber > bar.ber
		@echo ''
		@if cmp -s bar.ber att.ber; then\
		  echo "+++ Passed simple encode/decode tests using any.asn1.";\
		else\
		  echo "--- Failed simple encode/decode tests using any.asn1.";\
		fi
		@echo ''
		$(RM) foo.ber bar.ber

clean::
		$(RM) *.o *~ .emacs* core def indef genber att.ber $(ASN1HFILES) $(ASN1CFILES)
		$(RM) -r def-obj indef-obj
		$(RM) foo.ber bar.ber

depend::	$(SNACC)

#include ../../maketail

depend::
		cp dependencies deps
		for dir in def-obj indef-obj; do\
		  < dependencies sed -e 's:^\(.*\.o\):'"$$dir"'/\1:' >> deps;\
		done
		mv deps dependencies
